package org.javaz.ports;

import java.util.Comparator;
import java.util.Hashtable;

/**
 *
 */
public class HashtableComparator implements Comparator
{
	private Hashtable h = new Hashtable();

	public HashtableComparator(Hashtable h)
	{
		this.h = h;
	}

	public int compare(Object o1, Object o2)
	{
		if (h.containsKey(o1) && h.containsKey(o2))
		{
			Object o1b = h.get(o1);
			Object o2b = h.get(o2);
			if (o1b instanceof Number && o2b instanceof Number)
			{
				return ((Number) o1b).doubleValue() > ((Number) o2b).doubleValue() ? 1 : ((Number) o1b).doubleValue() < ((Number) o2b).doubleValue() ? -1 : 0;
			}
		}
		return 0;
	}
}
